home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / sysdeps / unix / start.c < prev    next >
C/C++ Source or Header  |  1993-12-20  |  3KB  |  102 lines

  1. /* Copyright (C) 1991, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with the GNU C Library; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <ansidecl.h>
  19. #include <errno.h>
  20. #include <stdlib.h>
  21. #include <unistd.h>
  22. #include <sysdep.h>        /* In case it wants to define anything.  */
  23.  
  24. /* The first piece of initialized data.  */
  25. int __data_start = 0;
  26.  
  27. #ifdef    DUMMIES
  28. #define    ARG_DUMMIES    DUMMIES,
  29. #define    DECL_DUMMIES    int DUMMIES;
  30. #else
  31. #define    ARG_DUMMIES
  32. #define    DECL_DUMMIES
  33. #endif
  34.  
  35. VOLATILE int errno;
  36.  
  37. #ifndef    HAVE_GNU_LD
  38. #undef    environ
  39. #define    __environ    environ
  40. #endif
  41.  
  42. char **__environ;
  43.  
  44. extern void EXFUN(__libc_init, (int argc, char **argv, char **envp));
  45. extern int EXFUN(main, (int argc, char **argv, char **envp));
  46.  
  47.  
  48. /* Not a prototype because it gets called strangely.  */
  49. static void start1();
  50.  
  51. #ifndef    HAVE__start
  52.  
  53. #if !defined (NO_UNDERSCORES) && defined (__GNUC__)
  54. /* Declare _start with an explicit assembly symbol name of `start'
  55.    (note no leading underscore).  This is the name vendor crt0.o's
  56.    tend to use, and thus the name most linkers expect.  */
  57. void _start (void) asm ("start");
  58. #endif
  59.  
  60. /* N.B.: It is important that this be the first function.
  61.    This file is the first thing in the text section.  */
  62. void
  63. DEFUN_VOID(_start)
  64. {
  65.   start1();
  66. }
  67.  
  68. #if !defined (NO_UNDERSCORES) && defined (HAVE_GNU_LD) && !defined (__GNUC__)
  69. /* Make an alias called `start' (no leading underscore,
  70.    so it can't conflict with C symbols) for `_start'.  */
  71. asm(".stabs \"start\",11,0,0,0");
  72. asm(".stabs \"__start\",1,0,0,0");
  73. #endif
  74.  
  75. #endif
  76.  
  77. /* ARGSUSED */
  78. static void
  79. start1(ARG_DUMMIES argc, argp)
  80.      DECL_DUMMIES
  81.      int argc;
  82.      char *argp;
  83. {
  84.   char **argv = &argp;
  85.  
  86.   /* The environment starts just after ARGV.  */
  87.   __environ = &argv[argc + 1];
  88.  
  89.   /* If the first thing after ARGV is the arguments
  90.      themselves, there is no environment.  */
  91.   if ((char *) __environ == *argv)
  92.     /* The environment is empty.  Make __environ
  93.        point at ARGV[ARGC], which is NULL.  */
  94.     --__environ;
  95.  
  96.   /* Do C library initializations.  */
  97.   __libc_init (argc, argv, __environ);
  98.  
  99.   /* Call the user program.  */
  100.   exit(main(argc, argv, __environ));
  101. }
  102.